package com.inspector.app.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.inspector.app.R;
import com.inspector.app.ui.chat.utils.ButtonUtils;

public class ImportView extends RelativeLayout implements View.OnClickListener {
    private View inflate;
    private RelativeLayout mInputBar;
    private LinearLayout mRightBtns;
    private static EditText mEdit;
    private static ImageView mImageAddButton;
    private static ImageView mSendButton;
    private static ImageView mVoiceBtn;
    private static RecordButton btnAudio;

    private static MorePanel morePanel;


    private onSendListener onSendListener;


    private boolean isKeyboardOpened = false;


    private boolean isActive = false;

    public void setOnSendListener(onSendListener onSendListener) {
        this.onSendListener = onSendListener;
    }

    public ImportView(Context context) {
        this(context, null);

    }

    public ImportView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImportView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    //绑定更多面板到输入框
    public static void setMoreView(MorePanel view) {
        morePanel = view;
    }

    /**
     * 初始化页面元素
     */
    private void initView() {
        inflate = LayoutInflater.from(getContext()).inflate(R.layout.import_view, this, true);

        mInputBar = findViewById(R.id.relative_input_bar);

        mRightBtns = findViewById(R.id.linear_right_area);

        mVoiceBtn = findViewById(R.id.image_voice);

        mVoiceBtn.setOnClickListener(this);

        mImageAddButton = findViewById(R.id.image_add_button);

        mSendButton = findViewById(R.id.send_button);

        btnAudio = findViewById(R.id.btnAudio);

        mSendButton.setOnClickListener(this);

        mEdit = findViewById(R.id.edit_content);

    }


    public static ImageView getAdd() {
        return mImageAddButton;
    }

    public static EditText getEdit() {
        return mEdit;
    }

    public static ImageView getVoice() {
        return mVoiceBtn;
    }

    public static RecordButton getAudioButton() {
        return btnAudio;
    }


    @Override
    public void onClick(View view) {
        if (ButtonUtils.isFastDoubleClick(view.getId())) return;
        if (view.getId() == R.id.send_button) {
            if (onSendListener != null) {
                String trim = mEdit.getText().toString();
                onSendListener.onSend(trim);
                // 清空EditText
                mEdit.setText("");
            }

        }


    }


    public interface onSendListener {
        void onSend(String content);
    }


}
